import java.util.Random;
import java.util.ArrayList;

class Deck {
    private ArrayList<Card> deck;
    private char[] suits = {'h', 'd', 'c', 's'};
    private static final int DECK_SIZE = 52;
    private static final int NUM_OF_SUITS = 4;
    private static final int NUM_OF_RANKS = 13;
    Deck() {
        deck = new ArrayList<Card>();
		for (int i = 0; i < NUM_OF_RANKS; i++) {
			for (int j = 0; j < NUM_OF_SUITS; j++) {
				try {
					deck.add(new Card(i, suits[j]));
				} catch (PokerException e) {
					System.out.println(e.getMessage());
					e.printStackTrace();
				}
			}
		}
		shuffle();
	}
	public void shuffle() {
		Random generator = new Random();
		Card temp;
		int j;
		for (int i = DECK_SIZE - 1; i > 0; i--) {
			j = generator.nextInt(i + 1);
			temp = deck.get(i);
			deck.set(i, deck.get(j));
			deck.set(j, temp);
		}
	}
	Card drawCard() {
		return deck.remove(0);
	}
	public int getSize() {
		return deck.size();
	}
	
	boolean findCard(final int rank, final char suit) {
	    Card card;
	    for (int i = 0; i < deck.size(); i++) {
	        card = deck.get(i);
	        if (card.getRank() == rank && card.getSuit() == suit) {
	            return true;
	        }
	    }
	    return false;
	}
	
	public String toString() {
		String result = "";
		for (int i = 0; i < deck.size(); i++) {
			result += deck.get(i).toString();
			result += " ";
		}
		return result;
	}
	void discardDeck() {
		deck = null;
	}
}
